import '../model/post_model.dart';

/// 植物养殖帖子默认数据
/// 提供8条默认的植物养殖帖子数据，包含2条视频类型
class PostData {
  /// 获取所有默认帖子数据
  static List<PostModel> getDefaultPosts() {
    final now = DateTime.now();

    return [
      // Post 1 - Plant Growth Challenge (Image)
      PostModel(
        id: '1',
        userId: '2', // admin
        category: PostCategory.plantGrowthChallenge,
        title: 'My Pothos 30-Day Growth Challenge Begins!',
        content:
            'Starting my pothos 30-day growth challenge today! I will record its growth progress daily and share care tips. Pothos is one of my favorite indoor plants - not only beautiful but also purifies the air. I will water and fertilize regularly while ensuring adequate sunlight. Excited to see it thrive!',
        tags: [
          'Pothos',
          'Growth Challenge',
          'Indoor Plants',
          'Care Tips',
          '30 Days',
        ],
        resourceType: ResourceType.image,
        resourcePath: 'assets/images/post1.png',
        publishTime: now.subtract(const Duration(days: 5)),
      ),

      // Post 2 - Herb Revival 30-Day Challenge
      PostModel(
        id: '2',
        userId: '2', // gardenmaster
        category: PostCategory.herbRevival30Day,
        title: 'Herb Revival Challenge: From Wilted to Reborn Miracle',
        content:
            'My rosemary and mint almost completely withered during winter, but I decided to give them a chance to revive! This 30-day challenge documents how I bring these herbs back to life through proper pruning, repotting, and fertilizing. Herbs are not only beautiful but also provide fresh seasonings for the kitchen.',
        tags: ['Herbs', 'Revival Challenge', 'Rosemary', 'Mint', 'Rebirth'],
        resourceType: ResourceType.image,
        resourcePath: 'assets/images/post2.png',
        publishTime: now.subtract(const Duration(days: 3)),
      ),

      // Post 3 - Upcycled Planter Green Challenge (Image)
      PostModel(
        id: '3',
        userId: '3', // leafyfriend
        category: PostCategory.upcycledPlanterGreen,
        title: 'Creative Planter DIY: Building Green Space with Waste Bottles',
        content:
            'Eco-friendly and beautiful! I created these creative planters using discarded glass bottles, plastic bottles, and tin cans. Each planter has a unique drainage system to ensure healthy plant growth. This not only reduces waste but also makes my balcony more interesting and personalized.',
        tags: [
          'DIY',
          'Eco-friendly',
          'Creative Planters',
          'Upcycling',
          'Green Living',
        ],
        resourceType: ResourceType.image,
        resourcePath: 'assets/images/post3.png',
        publishTime: now.subtract(const Duration(days: 2)),
      ),

      // Post 4 - Plant Growth Challenge (Image)
      PostModel(
        id: '4',
        userId: '4', // plantcare
        category: PostCategory.plantGrowthChallenge,
        title: 'Succulent Arrangement Care Tips Sharing',
        content:
            'Succulent arrangements are not only beautiful but also promote mutual growth. I selected different heights and colors of succulents to create rich visual layers. In care, I pay special attention to controlling watering and light exposure to ensure each plant gets the right growing environment.',
        tags: [
          'Succulents',
          'Arrangement',
          'Care Tips',
          'Visual Design',
          'Growing Environment',
        ],
        resourceType: ResourceType.image,
        resourcePath: 'assets/images/post4.png',
        publishTime: now.subtract(const Duration(days: 1)),
      ),

      // Post 5 - Herb Revival 30-Day Challenge (Image)
      PostModel(
        id: '5',
        userId: '5', // greensoul
        category: PostCategory.herbRevival30Day,
        title: 'Perfect Basil Revival Plan',
        content:
            'My basil almost completely died after a severe pest attack, but I didn\'t give up! Through careful pruning, soil replacement, and light adjustment, I successfully brought them back to life. Basil not only tastes delicious but also has great medicinal value.',
        tags: [
          'Basil',
          'Pest Control',
          'Soil Replacement',
          'Revival Plan',
          'Medicinal Value',
        ],
        resourceType: ResourceType.image,
        resourcePath: 'assets/images/post5.png',
        publishTime: now.subtract(const Duration(hours: 12)),
      ),

      // Post 6 - Upcycled Planter Green Challenge (Video)
      PostModel(
        id: '6',
        userId: '6', // blooming
        category: PostCategory.upcycledPlanterGreen,
        title: 'Old Tires Transformed into Garden Art',
        content:
            'Who says old tires can only be thrown away? I turned them into unique garden art! Through cutting, painting, and creative design, these tires not only became beautiful planters but also focal decorations in my garden. Each tire has a different design theme, filling the entire garden with artistic atmosphere.',
        tags: [
          'Old Tires',
          'Garden Art',
          'Creative Design',
          'Planter Makeover',
          'Art Decoration',
        ],
        resourceType: ResourceType.video,
        resourcePath: 'assets/videos/video2.mp4',
        coverImagePath: 'assets/images/video2.png',
        publishTime: now.subtract(const Duration(hours: 8)),
      ),

      // Post 7 - Plant Growth Challenge (Image)
      PostModel(
        id: '7',
        userId: '1', // plantlife
        category: PostCategory.plantGrowthChallenge,
        title: 'Perfect Hydroponic Plant Growth Record',
        content:
            'Hydroponic growing is both beautiful and practical. I chose pothos, spider plants, and lucky bamboo for hydroponic experiments. By controlling nutrient solution concentration and replacement frequency, these plants grew very well in water. Hydroponics is not only clean and hygienic but also allows clear observation of root growth.',
        tags: [
          'Hydroponics',
          'Pothos',
          'Spider Plant',
          'Lucky Bamboo',
          'Nutrient Solution',
        ],
        resourceType: ResourceType.image,
        resourcePath: 'assets/images/post6.png',
        publishTime: now.subtract(const Duration(hours: 4)),
      ),

      // Post 8 - Herb Revival 30-Day Challenge (Image)
      PostModel(
        id: '8',
        userId: '1', // naturelover
        category: PostCategory.herbRevival30Day,
        title: 'Thyme Winter Revival Miracle',
        content:
            'Thyme almost completely withered in the cold winter, but I brought it back to life through indoor insulation, reduced watering, and increased light exposure. Thyme is not only a delicious seasoning but also has great antibacterial and antioxidant properties. Now it has sprouted new buds, making me excited for spring!',
        tags: [
          'Thyme',
          'Winter Care',
          'Indoor Insulation',
          'Seasoning',
          'Antibacterial',
        ],
        resourceType: ResourceType.image,
        resourcePath: 'assets/images/post7.png',
        publishTime: now.subtract(const Duration(hours: 2)),
      ),

      // Post 9 - Image
      PostModel(
        id: '9',
        userId: '3', // leafyfriend
        category: PostCategory.plantGrowthChallenge,
        title: 'Pothos propagation success!',
        content:
            'Tried water propagation with pothos cuttings and got strong roots in two weeks. Here is today\'s potting result.',
        tags: ['Pothos', 'Propagation', 'Hydro'],
        resourceType: ResourceType.image,
        resourcePath: 'assets/images/post8.png',
        publishTime: now.subtract(const Duration(hours: 1, minutes: 30)),
      ),

      // Post 10 - Image
      PostModel(
        id: '10',
        userId: '5', // greensoul
        category: PostCategory.plantGrowthChallenge,
        title: 'Monstera new leaf unfurling',
        content:
            'Captured the magic moment of a new monstera leaf unfurling. The fenestrations look amazing!',
        tags: ['Monstera', 'New Leaf', 'Indoor'],
        resourceType: ResourceType.image,
        resourcePath: 'assets/images/post9.png',
        publishTime: now.subtract(const Duration(minutes: 50)),
      ),

      // Post 11 - Image
      PostModel(
        id: '11',
        userId: '2', // gardenmaster
        category: PostCategory.herbRevival30Day,
        title: 'Phalaenopsis spike care notes',
        content:
            'Sharing how I staked and misted my phalaenopsis to encourage blooms. Low, indirect light works best.',
        tags: ['Phalaenopsis', 'Bloom', 'Care'],
        resourceType: ResourceType.image,
        resourcePath: 'assets/images/post10.png',
        publishTime: now.subtract(const Duration(minutes: 40)),
      ),

      // Post 12 - Image
      PostModel(
        id: '12',
        userId: '6', // blooming
        category: PostCategory.upcycledPlanterGreen,
        title: 'Spider plant division update',
        content:
            'Separated spiderettes and repotted them. They adapt quickly and brighten the window shelf.',
        tags: ['Spider Plant', 'Repot', 'Division'],
        resourceType: ResourceType.image,
        resourcePath: 'assets/images/post11.png',
        publishTime: now.subtract(const Duration(minutes: 30)),
      ),

      // Post 13 - Image
      PostModel(
        id: '13',
        userId: '7', // plantlife
        category: PostCategory.plantGrowthChallenge,
        title: 'Rose pruning before spring',
        content:
            'Light pruning done to prepare for spring flush. Balanced shape and removed weak stems.',
        tags: ['Rose', 'Pruning', 'Spring'],
        resourceType: ResourceType.image,
        resourcePath: 'assets/images/post12.png',
        publishTime: now.subtract(const Duration(minutes: 20)),
      ),

      // Post 14 - Video
      PostModel(
        id: '14',
        userId: '1', // admin
        category: PostCategory.plantGrowthChallenge,
        title: 'Watering routine timelapse',
        content:
            'A short timelapse of today\'s watering routine across the shelf. Gentle shower + proper drainage.',
        tags: ['Timelapse', 'Watering', 'Routine'],
        resourceType: ResourceType.video,
        resourcePath: 'assets/videos/video1.mp4',
        coverImagePath: 'assets/images/video1.png',
        publishTime: now.subtract(const Duration(minutes: 10)),
      ),
    ];
  }

  /// 根据分类获取帖子
  static List<PostModel> getPostsByCategory(PostCategory category) {
    return getDefaultPosts()
        .where((post) => post.category == category)
        .toList();
  }

  /// 根据用户ID获取帖子
  static List<PostModel> getPostsByUserId(String userId) {
    return getDefaultPosts().where((post) => post.userId == userId).toList();
  }

  /// 根据资源类型获取帖子
  static List<PostModel> getPostsByResourceType(ResourceType resourceType) {
    return getDefaultPosts()
        .where((post) => post.resourceType == resourceType)
        .toList();
  }

  /// 根据标签获取帖子
  static List<PostModel> getPostsByTag(String tag) {
    return getDefaultPosts().where((post) => post.tags.contains(tag)).toList();
  }

  /// 获取热门帖子（按发布时间排序）
  static List<PostModel> getPopularPosts() {
    final posts = getDefaultPosts();
    posts.sort((a, b) => b.publishTime.compareTo(a.publishTime));
    return posts;
  }

  /// 获取最新帖子（按发布时间排序）
  static List<PostModel> getLatestPosts() {
    final posts = getDefaultPosts();
    posts.sort((a, b) => b.publishTime.compareTo(a.publishTime));
    return posts;
  }

  /// 获取所有标签（去重）
  static List<String> getAllTags() {
    final allTags = <String>{};
    for (final post in getDefaultPosts()) {
      allTags.addAll(post.tags);
    }
    return allTags.toList()..sort();
  }

  /// 获取各分类的帖子数量
  static Map<PostCategory, int> getCategoryCounts() {
    final counts = <PostCategory, int>{};
    for (final category in PostCategory.values) {
      counts[category] =
          getDefaultPosts().where((post) => post.category == category).length;
    }
    return counts;
  }

  /// 根据ID获取帖子
  static PostModel? getPostById(String id) {
    try {
      return getDefaultPosts().firstWhere((post) => post.id == id);
    } catch (e) {
      return null;
    }
  }
}
